package com.ysj.springboot.web.test1.controller;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * springboot 提供了JdbcTemplate 来进行数据库的操作
 */
@Controller
public class JdbcDataSourceController {
    @Autowired
    JdbcTemplate jdbcTemplate;

    @ResponseBody
    @RequestMapping("/dataSource")
    public Map<String,Object> getData(){
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from stu");
        return maps.get(0);
    }
}
